local math = math
local tostring = tostring
local string = string
local table_insert = table.insert
local filelog = require "filelog"
local base = require "base"
require "yydbenum"

local yydbTool = {}

function yydbTool.gen_all_randomcodes(code_nums)
	local all_randomcodes = {}
	local code_nums = code_nums or 1000
	local code_len = string.len(tostring(code_nums))

	for i = 1, code_nums do
		local temp_stringformat = "%0" .. tostring(code_len) .. "d"
		local temp_codes = string.format(temp_stringformat, i)
		table_insert(all_randomcodes, temp_codes)
	end
	for i = 1, #all_randomcodes do
		local change_index = base.get_random(1, #all_randomcodes)
		all_randomcodes[i], all_randomcodes[change_index] = all_randomcodes[change_index], all_randomcodes[i]
	end
	return all_randomcodes
end

function yydbTool.gen_randomcodes()
	local all_randomcodes = {}
	local code_nums = 9000
	local code_len = string.len(tostring(code_nums))

	for i = 1000, 9999 do
		local temp_stringformat = "%0" .. tostring(code_len) .. "d"
		local temp_codes = string.format(temp_stringformat, i)
		table_insert(all_randomcodes, temp_codes)
	end
	for i = 1, #all_randomcodes do
		local change_index = base.get_random(i, #all_randomcodes)
		all_randomcodes[i], all_randomcodes[change_index] = all_randomcodes[change_index], all_randomcodes[i]
	end
	return all_randomcodes
end

return yydbTool